package com.example.web.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.web.entity.User;
import com.example.web.tool.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
/**
 * http://localhost:8080/swagger-ui.html 
 * @author yzl
 *
 */
@Api(description = "用户信息接口管理", tags = "用户操作接口")
@RestController
public class UserController {

	/**
	 * 	增
	 * @param user
	 */
	@ApiOperation(value ="存用户",notes="提交xxx信息")
	@ApiImplicitParam(name ="user",value="用户对象",dataType="User")
	@PostMapping(value = "/user")
	public Result<User> saveUser(User user) {
		return Result.build(1, "success",user);
	}
	
	/**
	 * 	查
	 * @param name
	 * @param password
	 */
	@ApiOperation(value="查询单个用户",notes="依据{name：姓名，password：密码}查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name="name",value="用户姓名",required =true,dataType="String",paramType="path"),
		@ApiImplicitParam(name="password",value="用户密码",required =true,dataType="String",paramType="path")
	})
	@ApiResponses({
		@ApiResponse(code=400,message="请求参数没有问题"),
		@ApiResponse(code=404,message="请亲接口路径有误")
	})
	@GetMapping("/user/{name}/{password}")
	public Result<User>  getUser(@PathVariable("name")String name ,@PathVariable("password")String password) {
		User u =new User();
		u.setName(name);
		u.setAge("18");
		u.setCup("36D");
		u.setEmail("825620905@qq.com");
		u.setSex("女");
		u.setPassword(password);
		return Result.build(1, "success",u);
	}
	
	
	
}
